const API_HOST = "https://miniapp.growthupup.com/api/miniapp"
const ReqClient = (url, method, data) => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: API_HOST + url,
      method,
      data,
      success: (res) => resolve(res),
      fail: err => reject(err)
    })
  })
}

/* 
微信登录
*/
export const loginWithCode = ({
  code,
  business_id,
  avatarUrl,
  nickName,
  gender,
  country,
  province,
  city
}) => {
  return ReqClient(`/wechat/login_by_code`, "POST", {
    code,
    business_id,
    avatarUrl,
    nickName,
    gender,
    country,
    province,
    city

  })
}

/*
获取首页商品列表及信息
*/
export const getIndexPageData = (business_id) => {
  return ReqClient(`/product/list`, "GET", {
    business_id
  })
}

/* 
产品分类
*/
export const getCatalog = (business_id) => {
  return ReqClient(`/product/category`, "GET", {
    business_id
  })
}
/*
商品详情
*/
export const getProductDetail = (business_id, product_id, token) => {
  return ReqClient(`/product/detail`, "GET", {
    business_id,
    product_id,
    token
  })
}
/*
绑定手机
*/
export const bindPhone = (phone, code, openid, business_id) => {
  return ReqClient(`/wechat/register`, "POST", {
    phone,
    code,
    openid,
    business_id
  })
}
/*
获取短信验证码
*/
export const getSmS = (phone) => {
  return ReqClient(`/wechat/sendSms`, "POST", {
    phone
  })
}
/*
添加到购物车
*/
export const addToCar = (token, id) => {
  return ReqClient(`/cart/add`, "POST", {
    token,
    id
  })
}
/* 
立即购买/加入订单
*/
// export const addOrder = ()
/*
购物车商品列表
*/
export const getCarList = (token) => {
  return ReqClient(`/cart/list`, "GET", {
    token,
  })
}
/* 
移出购物车列表
*/
export const removeFromCar = (token, id) => {
  return ReqClient(`/cart/remove`, "DELETE", {
    token,
    id
  })
}
/* 
获取商品搜索列表
*/
export const getProductList = (business_id, options, token, order_by,form) => {
  return ReqClient(`/product/search`, "POST", {
    ...options,
    business_id,
    token,
    order_by,
    ...form
  })
}
/*
收货地址列表
*/
export const getAddressList = (token) => {
  return ReqClient(`/delivery/list`, "GET", {
    token
  })
}
/*
添加收货地址
*/
export const addAddress = ({
  token,
  name,
  phone,
  province,
  city,
  district,
  address,
  is_default
}) => {
  return ReqClient(`/delivery/add`, "POST", {
    token, //用户验证
    name, //收货人姓名
    phone, //电话
    province, //省份
    city, //城市
    district, //区
    address, // 地址
    is_default
  })
}
/*
获取全国省市区
*/
export const getRegion = () => {
  return ReqClient(`/dropdown/address`, "GET", {})
}
/*
代金券列表
*/
export const getCouponList = (token) => {
  return ReqClient(`/ticket/list`, "GET", {
    token
  })
}
/*
立即创建订单
*/
export const addOrder = (token, product_ids, delivery_id, total_price, ticket_id, remark) => {
  return ReqClient(`/order/add`, "POST", {
    token,
    product_ids,
    delivery_id,
    total_price,
    ticket_id,
    remark
  })
}
/*
修改收货地址
*/
export const updateAddress = ({
  id,
  token,
  name,
  phone,
  province,
  city,
  district,
  address,
  is_default
}) => {
  return ReqClient(`/delivery/update`, "POST", {
    id,
    token, //用户验证
    name, //收货人姓名
    phone, //电话
    province, //省份
    city, //城市
    district, //区
    address, // 地址
    is_default
  })
}
/*
获取代金券详情
*/
export const getCouponDetail = (business_id) => {
  return ReqClient(`/ticket/detail`, "GET", {
    business_id
  })
}
/*
领取代金券
*/
export const receiveCoupon = (token, ticket_id, business_id) => {
  return ReqClient(`/ticket/add`, "POST", {
    token,
    ticket_id,
    business_id
  })
}
/*
创建订单
*/
export const createOrder = (token,
  product_ids,
  delivery_id,
  pay_price,
  ticket_id,
  remark,
  order_enter_type) => {
  return ReqClient(`/order/add`, "POST", {
    token,
    product_ids,
    delivery_id,
    pay_price,
    ticket_id,
    remark,
    order_enter_type
  })
}
/*
订单列表
 */
export const getOrderList = (token) => {
  return ReqClient(`/order/list`, "GET", {
    token
  })
}
/*
取消订单
*/
export const cancelOrder = (token, batchcode) => {
  return ReqClient(`/order/remove`, "PUT", {
    token,
    batchcode
  })
}
/*
获取订单详情
*/
export const getOrderDetail = (token, batchcode) => {
  return ReqClient(`/order/detail`, "GET", {
    token,
    batchcode
  })
}
/*
地址删除
*/
export const deleteAddress = (token, id) => {
  return ReqClient(`/delivery/remove`, "DELETE", {
    token,
    id
  })
}
/*
获取地址详情
*/
export const getAddressInfo = (token, id) => {
  return ReqClient(`/delivery/info`, "GET", {
    token,
    id
  })
}
/*
获取订单统计记录
*/
export const getOrderRecord = (token) => {
  return ReqClient(`/order/stats`, "GET", {
    token
  })
}
/*
获取默认地址
*/
export const getDefaultAddress = (token) => {
  return ReqClient(`/delivery/default`, "GET", {
    token
  })
}
/*
常见问题列表
*/
export const getQuestionList = (business_id) => {
  return ReqClient(`/question/list`, "GET", {
    business_id
  })
}
/*
常见问题详情
*/
export const getQuestionDetail = (id, business_id) => {
  return ReqClient(`/question/info`, "GET", {
    id,
    business_id
  })
}
/*
微信支付
*/
export const wxPay = ({
  token,
  business_id,
  openid,
  total_fee,
  ...rest
}) => {
  return ReqClient(`/wechat/pay`, "POST", {
    token,
    business_id,
    openid,
    ...rest,
    total_fee
  })
}
/*
意见反馈 图片上传
*/
export const uploadFeedbackImg = `${API_HOST}/upload/upload_picture`
/*
意见反馈
*/
export const addFeedback = (content,
  contact,
  token,
  business_id,
  images) => {
  return ReqClient(`/feedback/post`, "POST", {
    type: 1,
    content,
    contact,
    token,
    business_id,
    images,
  })
}
/*
  确认收货
*/
export const confirmReceipt = (token, batchcode) => {
  return ReqClient(`/order/confirm`, "POST", {
    token,
    batchcode
  })
}
/* 
提醒发货
*/
export const remindShip = (token,
  batchcode,
  business_id) => {
  return ReqClient(`/message/message_order`, "POST", {
    token,
    batchcode,
    business_id
  })
}
/**
 * 系统消息
 */
export const getSystemMsg = (token) => {
  return ReqClient(`/message/message_system`, "GET", {
    token
  })
}
/**
 * 确认收货
 */
export const comfirmOrder = (token, batchcode) => {
  return ReqClient(`/order/confirm`, "POST", {
    token,
    batchcode
  })
}

/*
修改人：颜阁
修改时间：2018-11-09
修改内容:主页优惠券弹窗
 */

export const indeAlert = (token, business_id) => {
  return ReqClient(`/ticket/coupon_custom_list`, "POST", {
    token,
    business_id
  })
}

/*
修改人:邵群
修改时间：2018-11-13
修改内容:获取banner
 */
export const bannerList = (business_id) => {
  return ReqClient(`/banner/banner_list`, "POST", {
    business_id
  })
}

export const mainBanner = (token) => {
  return ReqClient(`/banner/main_banner`, "POST", {
    token
  })
}
/**
 *添加人：邵群
  添加时间：2018-11-26
  添加内容：活动接口
 * */
//  首页获取活动列表
export const activityList = (business_id) => {
  return ReqClient(`/activity/get_activity`, "POST", {
    business_id
  })
}
// 获取活动详情页
export const activityDetail = (token, id) => {
  return ReqClient(`/activity/get_activity_detail`, "POST", {
    token,
    id
  })
}
/**
 *添加人：颜阁
  添加时间：2018-11-28
  添加内容：活动优惠券
 * */
export const getCouponAdd = (token, business_id) => {
  return ReqClient(`/ticket/get_coupon_add`, "POST", {
    token,
    business_id
  })
}
export const addHandCoupon = (token, business_id, id) => {
  return ReqClient(`/ticket/add_hand_coupon`, "POST", {
    token,
    business_id,
    id
  })
}
// 收藏商品
export const collectGoods = ({
  product_id,
  token
}) => {
  return ReqClient(`/wishlist/add_del`, "POST", {
    product_id,
    token
  })
}
// 收藏列表
export const wishList = ({
  business_id,
  token
}) => {
  return ReqClient(`/wishlist/list`, "POST", {
    business_id,
    token
  })
}

/**
 * 分享商城小程序二维码
 */
export const createQrcode = (token) => {
  return ReqClient(`/erweima/create_qrcode`, "GET", {
    token
  })
}
/**
 * 分享商城商品详情小程序二维码
 */
export const createDetailQrcode = (token, product_id) => {
  return ReqClient(`/erweima/create_detail_qrcode`, "GET", {
    token,
    product_id
  })
}

/**
 * 分享采集
 */
export const getBeShared = (token, parent_id, product_id, name) => {
  return ReqClient(`/erweima/get_be_shared`, "POST", {
    token,
    parent_id,
    product_id,
    name
  })
}
/**
 * 根据产品获取满足条件的优惠卷
 */
export const getUseCoupon = (token, product_ids, total_price) => {
  return ReqClient(`/ticket/get_use_coupon`, "POST", {
    token,
    product_ids,
    total_price
  })
}


// 客服问题列表
export const customerList = (business_id) => {
  return ReqClient(`/customer/list`, "GET", {
    business_id
  })
}
// 支付推送
export const sendTemplateAfterPay = (token, prepay_id, batchcode, money) => {
  return ReqClient(`/miniapp/send_template_after_pay`, "POST", {
    token,
    prepay_id,
    batchcode,
    money
  })
}

// 七牛token
export const getToken = () => {
  return ReqClient('/upload/token', "POST", {})
}


// 手机区号获取
export const smsCountry = () => {
  return ReqClient('/wechat/smsCountry', "GET", {})
}

// 售后申请
export const refund = (token, info_batchcode, money, pics, content) => {
  return ReqClient(`/order/refund`, "POST", {
    token,
    info_batchcode,
    money,
    pics,
    content
  })
}

// 售后详情
export const refundDetail = (token, info_batchcode) => {
  return ReqClient(`/order/refund_detail`, "GET", {
    token,
    info_batchcode
  })
}

//储存formID
export const addFormId = (token, form_id, type) => {
  return ReqClient(`/notice/addFormId`, "POST", {
    token,
    form_id,
    type
  })
}


/**
 * 数据统计
 */
export const miniappLog = (token, data) => {
  return ReqClient(`/miniapp/log`, "POST", {
    token,
    data
  })
}

/**
 * 商品详情坑位
 */
export const detailLog = (business_id, token, product_id,enter_type, label, position) => {
  return ReqClient(`/product/detail_log`, "GET", {
    business_id, 
    token,
    product_id,
    enter_type,
    label,
    position
  })
}
/*
用户寄卖列表
*/
export const resellList = (token) => {
  return ReqClient(`/resell/resell_list`, "POST", {
    token
  })
}
/*
获取寄卖商品的详情
*/
export const productInfo = (token, resell_id) => {
  return ReqClient(`/resell/product_info`, "POST", {
    token,
    resell_id
  })
}
/*
用户确认寄卖
*/
export const userConfirm = (token, resell_id, user_confirm) => {
  return ReqClient(`/resell/user_confirm`, "POST", {
    token,
    resell_id,
    user_confirm
  })
}
/*
用户寄卖列表
*/
export const userConfirmDelivery = (token, resell_id) => {
  return ReqClient(`/resell/user_confirm_delivery`, "POST", {
    token,
    resell_id
  })
}
/*
获取默认银行卡
*/
export const defaultBankcard = (token) => {
  return ReqClient(`/bankcard/default_bankcard`, "POST", {
    token
  })
}

/**
 *  点击客服埋点记录
 */
export const customerServiceLog = (token, type, product_id, batchcode) => {
  return ReqClient(`/customer/customer_service_log`, "POST", {
    token,
    type,
    product_id,
    batchcode
  })
}
// 添加寄卖商品
export const addProduct = (token, froms) => {
  return ReqClient(`/resell/add_product`, "POST", {
    token,
    ...froms
  })
}
/*
预约顺丰快递
*/
export const addSforder = (token, id, delivery_id, send_time) => {
  return ReqClient(`/delivery/add_sforder`, "POST", {
    token,
    id,
    delivery_id,
    send_time
  })
}
/*
预约去发货
*/
export const goDelivery = (token, product_id, shipping_company, shipping_sn, shipping_pic) => {
  return ReqClient(`/delivery/go_delivery`, "POST", {
    token,
    product_id,
    shipping_company,
    shipping_sn,
    shipping_pic
  })
}
/*
获取商家默认地址
*/
export const getPlatformAddress = (token) => {
  return ReqClient(`/resell/get_platform_address`, "POST", {
    token
  })
}
/*
获取银行卡列表
*/
export const bankcardList = (token, id) => {
  return ReqClient(`/bankcard/bankcard_list`, "POST", {
    token,
    id
  })
}
/*
获取省市
*/
export const getProvinces = () => {
  return ReqClient(`/city/getProvinces`, "POST", {
  })
}
/*
获取银行列表
*/
export const bankList = () => {
  return ReqClient(`/bankcard/bank_list`, "POST", {
  })
}
/*
获取支行列表
*/
export const bankBranchInfo = (provinceCode, cityCode, headBankCode) => {
  return ReqClient(`/bankcard/bankBranchInfo`, "POST", {
    provinceCode,
    cityCode,
    headBankCode
  })
}
/*
添加银行卡
*/
export const addBank = (token, formms) => {
  return ReqClient(`/bankcard/add_bank`, "POST", {
    token,
    ...formms
  })
}
/*
修改银行卡
*/
export const upBank = (token, bank_id, formms) => {
  return ReqClient(`/bankcard/up_bank`, "POST", {
    token,
    bank_id,
    ...formms
  })
}
/* 
品牌搜索
*/
export const brandLike = (brand_name) => {
  return ReqClient(`/resell/brand_like`, "POST", {
    brand_name
  })
}
/* 
取消顺丰快递
*/
export const cancelSforder = (token, order_id, id) => {
  return ReqClient(`/delivery/cancel_sforder`, "POST", {
    token, 
    order_id, 
    id
  })
}
/* 
获取规则
*/
export const resellRule = (business_id) => {
  return ReqClient(`/resell/rule`, "POST", {
    business_id
  })
}
/* 
获取频道
*/
export const channelList = (business_id) => {
  return ReqClient(`/channel/channel_list`, "POST", {
    business_id
  })
}
/* 
获取频道中的商品
*/
export const channelProducts = (token, id, page, order_by, category) => {
  return ReqClient(`/channel/channel_order`, "POST", {
    token,
    id,
    page,
    order_by,
    category
  })
}
/* 
获取二级分类列表
*/
export const categoryType = () => {
  return ReqClient(`/dropdown/category_type`, "GET", {
  })
}
/* 
砍价--可砍商品列表
*/
export const productCutList = (token, business_id,page) => {
  return ReqClient(`/cutprice/product_cut_list`, "POST", {
    token,
    business_id,
    page
  })
}
/* 
砍价--自己的砍价商品页
*/
export const cutpriceHome= (token, product_id) => {
  return ReqClient(`/cutprice/home`, "POST", {
    token,
    product_id
  })
}
/* 
砍价--自己的砍价商品页
*/
export const cutpriceCut = (token, product_id, parent_id) => {
  return ReqClient(`/cutprice/cut`, "POST", {
    token,
    product_id,
    parent_id
  })
}
/* 
商品详情里的推荐商品
*/
export const productsFeatured = (token, product_id) => {
  return ReqClient(`/cutprice/products_featured`, "POST", {
    token,
    product_id
  })
}
/* 
活动列表页
*/
export const myProductsFeatured = (token) => {
  return ReqClient(`/cutprice/my_products_featured`, "POST", {
    token
  })
}
/* 
砍价---好友的砍价商品页
*/
export const cutpriceFriendHome = (token, parent_id, product_id) => {
  return ReqClient(`/cutprice/friend_home`, "POST", {
    token,
    parent_id,
    product_id
  })
}
/* 
砍价活动成功分享砍价商品二维码
*/
export const createCutpriceQrcode = (token, path, product_id) => {
  return ReqClient(`/erweima/create_cutprice_qrcode`, "GET", {
    token,
    path,
    product_id
  })
}
/* 
获取二维码入口数据
*/
export const cutBeShared = (token, source, parent_id, product_id) => {
  return ReqClient(`/erweima/cut_be_shared`, "GET", {
    token,
    source,
    parent_id,
    product_id
  })
}
/* 
获取活动规则
*/
export const cutRegle = () => {
  return ReqClient(`/cutprice/regle`, "GET", {
  })
}
/* 
我的砍价商品下的推荐
*/
export const myCutFeatured = (token) => {
  return ReqClient(`/cutprice/my_cut_featured`, "POST", {
    token
  })
}
//获取二维码入口
export const beShared = ({token,source,user_id}) => {
  return ReqClient(`/erweima/be_shared`, "GET", {
    token,
    source,
    user_id
  })
}
export const onShared = ({ token, source, parent_id }) => {
  return ReqClient(`/erweima/be_shared`, "GET", {
    token,
    source,
    parent_id
  })
}
export const onlistShared = ({ token, source ,parent_id, product_id}) => {
  return ReqClient(`/erweima/be_shared`, "GET", {
    token,
    source,
    parent_id,
    product_id
  })
}
